import express from "express";
import http from "http";
// import { initRouter } from "./router";
import { setupExpress } from "./setup";
import { catchError } from "./catch";
import { setupSocket } from "./socket";

const app = express();
const server = http.createServer(app);

let path0 = "/v1";

const apps = ["user", "order", "test", "shop", "adm", "fun", "third", "admin"];

setupExpress(app, path0);

setupSocket(server);

app.get([path0, "/"], async (req, res) => {
  res.send({
    host: req.hostname,
    origin: req.origin,
    _body: req._body,
    path0: req.path0,
  });
});

apps.forEach((name) => {
  app.use(path0 + "/" + name, require("./router/" + name));
});

catchError(app);

const port = process.env.PORT || 6011;
server.listen(port, () => {
  console.log(`server running http://localhost:${port}${path0}`);
});
